package za.org.jcicada.genss.alarm.impl;

import java.util.EnumMap;
import java.util.Map;

import za.org.jcicada.genss.alarm.AlarmStatus;
import za.org.jcicada.genss.alarm.IAlarmRule;
import za.org.jcicada.genss.sensor.ISensor;
import za.org.jcicada.genss.sensor.SensorStatus;
import za.org.jcicada.genss.sensor.impl.SensorStatusValue;

/**
 * Specialised alarm rule that just uses the sensor status to determine the
 * alarm status, ie the alarm changes when the sensor status changes.
 * 
 * @author rcrida
 * 
 */
public class AlarmRuleStatus implements IAlarmRule {

    /**
     * Map from sensor status to corresponding alarm status.
     */
    private final Map<SensorStatus, AlarmStatus> statusMap = new EnumMap<SensorStatus, AlarmStatus>(SensorStatus.class);

    /**
     * Constructor the object and initialize the status map.
     */
    public AlarmRuleStatus() {
        statusMap.put(SensorStatus.UNKNOWN, AlarmStatus.CLEAR);
        statusMap.put(SensorStatus.NOMINAL, AlarmStatus.CLEAR);
        statusMap.put(SensorStatus.WARN, AlarmStatus.WARNING);
        statusMap.put(SensorStatus.ERROR, AlarmStatus.FUNCTIONAL);
        statusMap.put(SensorStatus.FAILURE, AlarmStatus.FAILURE);
    }

    /**
     * Calculates a status by just looking up a value given the sensor status.
     * 
     * @param sensor the sensor object
     * @param value the current sensor value
     * @return the alarm status
     */
    public AlarmStatus calcStatus(ISensor sensor, SensorStatusValue statusValue) {
    	return statusMap.get(statusValue.getStatus());
    }

}
